#ifndef FILE_READER_H
#define FILE_READER_H

#include <stdio.h>
#include <dirent.h>
#include <iostream>


using namespace std;


class FileReader {
		public:
			
		FileReader(): mem(0){}
				
		int getFileSize(const char* filename){
				struct stat results;
				stat(filename, &results);
				return results.st_size;
		}

		char *mem;
		int filesize;
		
		void read(string filename) {
		
			filesize = getFileSize(filename.c_str());

			if (mem) delete [] mem;
			mem = new char[filesize];
		
			FILE *fs = fopen(filename.c_str(), "r");
			if (fs==NULL) {
				printf("\033[22;31merror: can't read the file\033[22;35m '%s'\033[22;30m\n", filename.c_str()); 
				return;
			}
			
			fread(mem, 1, filesize, fs); 
			
			fclose(fs);
		}
};

#endif
